<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="oneroom.user.addSeach.addressModel" %>
<%@ page import="oneroom.admin.code.codeModel" %>
<%@ page import="oneroom.admin.code.codeDao" %>
<jsp:useBean id="codeDao" 	scope="page" class="oneroom.admin.code.codeDao" />
<jsp:useBean id="dao" 		scope="page" class="oneroom.user.zip.zipcode" />
<jsp:useBean id="adddao" 	scope="page" class="oneroom.user.addSeach.addressDao" />
<%
	List zipcode2List = dao.getZipcode2(); //주소 검색시 도를 보여준다.
	codeDao kindCode = new codeDao();
	List kindList = kindCode.getDtlList("500");
	String pageName = "area_list.jsp";
	String viewName = "area_view.jsp";
	int     giSelectPage  	= Integer.parseInt(request.getParameter("txtSelectPage") == null ? "0" :request.getParameter("txtSelectPage"));			//현재 선택된 페이지 저장
	int     giSelectBlock 	= Integer.parseInt(request.getParameter("txtSelectBlock") == null ? "0" :request.getParameter("txtSelectBlock"));			//현재 선택된 블락페이지 저장
	//검색 부분
	String roomkind 	= request.getParameter("roomkind") 	== null ? "" : request.getParameter("roomkind");
	roomkind 			= roomkind.equals("no") ? "" : roomkind;
	String charter 		= request.getParameter("charter") 	== null ? "" : request.getParameter("charter");
	String zipcode2 	= request.getParameter("zipcode2") 	== null ? "" : request.getParameter("zipcode2");
	String zipcode3 	= request.getParameter("zipcode3") 	== null ? "" : request.getParameter("zipcode3");
	String[] dong 		= request.getParameterValues("dong"); 
	String roommoney 	= request.getParameter("roommoney") 	== null ? "" : request.getParameter("roommoney");
	String deposit 		= request.getParameter("deposit") 	== null ? "" : request.getParameter("deposit");
	String month 		= request.getParameter("month") 	== null ? "" : request.getParameter("month");
	String sort 		= request.getParameter("sort") 		== null ? "date" : request.getParameter("sort");
	int     giCount       	= 0;			//리스트 for문 break문에 사용
	int     giRecordcnt   	= 0;			//리스트의 카운터에 사용
	int     giPageSize    	= 10;  			// 한페이지에 나타내고자 하는 List수
	int     giBlockSize   	= 10;   		// Block의 수
	int     giCurPage     	= 1;   			// 현재 Page
	int     giCurBlock    	= 0;   			// 현재 Block
	int     giStartPos    	= 0;   			// 시작 List 위치
	int     giTotPage     	= 0;   			// 총 Page수
	int     giTotBlock    	= 0;   			// 총 Block수
	//  넘겨온 값 받기(List페이지 관련)...
	if ( giSelectPage  >  0 ) { 			// 선택된 Page값이 있을경우....     
		giCurPage  = giSelectPage;   	// 현재Page = 선택된Page 
		giCurBlock = giSelectBlock;  	// 블락page = 선택된 블락 page
	}
	//쿼리를 돌려서 가지고 오는 값
	
	List roomList  = adddao.getAddress( roomkind, 
				 charter, 
				 zipcode2,
				 zipcode3,
				 dong,
				 roommoney,  
				 deposit,  
				 month,
				 sort,
				 giSelectPage, 
				 giPageSize);
	if (roomList.size() > 0 ) {
		//전체 게시물 수
		giRecordcnt = adddao.getCount(roomkind, 
									 charter, 
									 zipcode2,
									 zipcode3,
									 dong,
									 roommoney, 									 
									 deposit, 
									 month); 			// 총 list 수
	}
	if (giRecordcnt > 0) {  // 조건에 맞는 값이 있으면....
		giTotPage  = giRecordcnt / giPageSize;
		if (giRecordcnt % giPageSize != 0) {
			giTotPage = giTotPage + 1;			// 총 Page수를 구한다...
		}
		giTotBlock = giTotPage / giBlockSize;
		if (giTotPage % giBlockSize != 0) {
			giTotBlock = giTotBlock + 1;		// 총 Block수를 구한다...
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>원룸몬스터</title>
<link href="/room/css/all.css" rel="stylesheet" type="text/css" />
<script src="/room/script/swfobject_modified.js" type="text/javascript"></script>
<script src="/room/script/common.js" type="text/javascript"></script>
<script src="/room/script/jquery-1.3.2.min.js" type="text/javascript" ></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
	<%if(!zipcode2.equals("")){ //주소 검색을 하였을 경우 주소 선택한 항목에 보여주기 위한 작업 시 구주소가지고옴%>
	$.ajax({type : "post",
		url : "/room/area/areacode.jsp",
		dataType : "html",
		data : "zip_code2=<%=zipcode2%>&zip_code3=<%=zipcode3%>",
		success : function(msg){
			document.getElementById("zip3").innerHTML = msg;
		}
	});
	<%}%>
	<%if(!zipcode3.equals("")){ //주소 검색을 하였을 경우 주소 선택한 항목에 보여주기 위한 작업 시 구주소가지고옴%>
		$.ajax({type : "post",
			url : "/room/area/areadong.jsp",
			dataType : "html",
			data : "roomkind=<%=roomkind%>&charter=<%=charter%>&zip_code3=<%=zipcode3%>&dong=<%if(dong!=null){for(int i=0; i<dong.length; i++){if((i+1)==dong.length){out.print(dong[i]);}else{out.print(dong[i]+",");}}}%>",
			success : function(msg){
				document.getElementById("zipdong").innerHTML = msg;
			}
		});
		<%}%>
	$('#zipcode2').change(function() {//AJAX로 주소 가지고옴 시 구를 가지고옴 
		$.ajax({type : "post",
			url : "/room/area/areacode.jsp",
			dataType : "html",
			data : "zip_code2="+document.getElementById("zipcode2").value,
			success : function(msg){
				document.getElementById("zip3").innerHTML = msg;
			}
		});
	});
	$('#seach').click(function() {
		
		if(document.getElementById("roomkind").value == ""){
			alert("임태종류를 선택하십시오.");
			return ;
		}
		if(document.getElementById("zipcode2").value == "" && document.getElementById("zipcode3").value == ""){
			alert("지역를 선택하십시오.");
			return ;
		}
		document.getElementById("frm").submit();
	});
	$('#datesort').click(function() {
		document.getElementById("sort").value="date";
		document.getElementById("frm").submit();
	});
	$('#depositsort').click(function() {
		document.getElementById("sort").value="deposit";
		document.getElementById("frm").submit();
	});
	$('#monthsort').click(function() {
		document.getElementById("sort").value="month";
		document.getElementById("frm").submit();
	});
	$('#re').click(function() {
		location.href="zip_list.jsp";
	});

});

function zipCode3(){
	var roomkind = document.getElementById("roomkind").value;	
	//$('#zipcode3').change(function() {//AJAX로 주소 가지고옴 읍면동을 가지고옴
		$.ajax({type : "post",
			url : "/room/area/areadong.jsp",
			dataType : "html",
			data : "roomkind="+roomkind+"&charter="+$(':radio[name="charter"]:checked').val()+"&zip_code3="+document.getElementById("zipcode3").value,
			success : function(msg){
				document.getElementById("zipdong").innerHTML = msg;
			}
		});
	//});
}

function goView(oneroomseq){
	document.frmView.oneroom_seq.value = oneroomseq;
	document.frmView.submit();
}

function display(no){
    for(var i=1; i<=2; i++){
        document.getElementById("charter_type"+i).style.display="none";
    }
    document.getElementById("charter_type"+no).style.display="block";
    if(no == "2"){
    	document.getElementById("charter_name").innerHTML = "보증금/월세";
    }else{
    	document.getElementById("charter_name").innerHTML = "전세금";
    }
}
//-->
</script>

</head>

<body onload="display('<%=charter=="J"? "1":"2"%>');">
<div align="center"> 

 <div id="content">

<!----------------왼쪽---------------->  
  <%@ include file="/room/common/left.jsp" %> 
<!----------------왼쪽끝---------------->  


<!----------------가운데 시작----------------> 
 <div id="rgt">
  <div id="con01">
   <div class="top bb1"><img src="/room/img/txt_top.gif" /></div>
   
   <div id="sch-adress">
   	<form action="area_list.jsp" method="post" name="frm" id="frm">
   	<input type="hidden" name="sort" value="<%=sort %>" id="sort" />
   	<input type="hidden" name="roomkind" value="<%=roomkind %>" id="roomkind" />
     <div><img src="/room/img/title_adress.gif"/></div>
     <div class="bg_adress">
      
      <div class="pt15">
      <table width="400px;" border="0" cellspacing="0" cellpadding="0">
      <col width="5px" />
      <col width="70px" />
      <col width="120px" />
      <col width="5px" />
      <col width="70px" />
      <col width="130px" />
       <tr>
        <td><img src="/room/img/icon_point.gif"/></td>
        <td><span class="fw">임대종류</span></td>
        <td><select class="w100" name="roomkind" id="roomkind" disabled="disabled">
        <option value="">선택</option>
        <%for(int i=0; i<kindList	.size(); i++){ %>
        <% codeModel mod = (codeModel)kindList.get(i); %>
         <option value="<%=mod.getCode() %>" <%if(roomkind.equals(mod.getCode())){out.print("selected='selected'");} %>><%=mod.getCodename() %></option>
         <%} %>
        </select></td>
        <td><img src="/room/img/icon_point.gif"/></td>
        <td><span class="fw">임대형태</span></td>
		<td><input type="radio" name="charter" value="W" onclick="display('2');" <%if(charter.equals("") || charter.equals("W")){out.print("checked='checked'");}  %>></input> 월세 &nbsp;&nbsp;
        <input type="radio" name="charter" value="J" onclick="display('1');"<%if(charter.equals("J")){out.print("checked='checked'");}  %>></input> 전세</td>
       </tr>
      </table>
      </div>
     
     <div class="pt10">
       <table width="370px;" border="0" cellspacing="0" cellpadding="0">
      <col width="5px" />
      <col width="70px" />
      <col width="120px" />
      <col width="170px" />
       <tr>
        <td><img src="/room/img/icon_point.gif"/></td>
        <td><span class="fw">지역</span></td>
        <td>
        	<div id="zip2">
				<select name="zipcode2" id="zipcode2" class="w100">
				<option value="">선택</option>
				<%
					for(int i = 0; i<zipcode2List.size(); i++){ 
						String zipcode2Value = (String)zipcode2List.get(i);
				%>
					<option value="<%=zipcode2Value %>" <%if(zipcode2.equals(zipcode2Value)){out.print("selected='selected'");} %>><%=zipcode2Value %></option>
				<%} %>
				</select>
			</div>
        </td>
        <td><div id="zip3">	
				<select name="zipcode3" id="zipcode3" class="w120">
					<option value="">선택</option>
				</select>
				</div>
		</td>
       </tr>
      </table>
     </div>
     
      <div class="pt10">
      <table width="600px;" border="0" cellspacing="0" cellpadding="0">
      <col width="600px" />
      <tr>
        <td>
        <div id="zipdong">지역을 선택 하십시요.</div>
        </td>
       </tr>
      </table>
      </div>
      
       <div class="pt10 pb10">
      <table width="570px;" border="0" cellspacing="0" cellpadding="0">
      <col width="5px" />
      <col width="70px" />
      <col width="20px" />
      <col width="5px" />
      <col width="40px" />
      <col width="230px" />
      <col width="200px" />
       <tr>
        <td><img src="/room/img/icon_point.gif"/></td>
        <td><span class="fw" id="charter_name">전세금</td>
        <td>
        <div id="charter_type1"  style="display: none;">
        <select name="roommoney" id="roommoney" class="w100">
					<option value="" >선택</option>
					<option value="2000" <%if(roommoney.equals("2000")){out.print("selected='selected'");} %>>2천~3천</option>
					<option value="3000" <%if(roommoney.equals("3000")){out.print("selected='selected'");} %>>3천~5천</option>
					<option value="5000" <%if(roommoney.equals("5000")){out.print("selected='selected'");} %>>5천~7천</option>
					<option value="7000" <%if(roommoney.equals("7000")){out.print("selected='selected'");} %>>7천~1억</option>
					<option value="10000" <%if(roommoney.equals("10000")){out.print("selected='selected'");} %>>1억이상</option>
				</select>       
		</div>		
        <div id="charter_type2"  style="display: block;">
        <select name="deposit" id="deposit" class="w100">
					<option value="" >선택</option>
					<option value="100" <%if(deposit.equals("100")){out.print("selected='selected'");} %>>100만이하</option>
					<option value="200" <%if(deposit.equals("200")){out.print("selected='selected'");} %>>200만</option>
					<option value="300" <%if(deposit.equals("300")){out.print("selected='selected'");} %>>300만</option>
					<option value="500" <%if(deposit.equals("500")){out.print("selected='selected'");} %>>500만</option>
					<option value="1000" <%if(deposit.equals("1000")){out.print("selected='selected'");} %>>1000만</option>
					<option value="1500" <%if(deposit.equals("1500")){out.print("selected='selected'");} %>>1500만</option>
					<option value="2000" <%if(deposit.equals("2000")){out.print("selected='selected'");} %>>2천~3천</option>
					<option value="3000" <%if(deposit.equals("3000")){out.print("selected='selected'");} %>>3천~5천</option>
					<option value="5000" <%if(deposit.equals("5000")){out.print("selected='selected'");} %>>5천~1억</option>
					<option value="10000" <%if(deposit.equals("10000")){out.print("selected='selected'");} %>>1억이상</option>
				</select>        
        <select name="month" id="month" class="w100">
					<option value="">선택</option>
					<option value="0" <%if(month.equals("0")){out.print("selected='selected'");} %>>10만이하</option>
					<option value="10" <%if(month.equals("10")){out.print("selected='selected'");} %>>10~30만</option>
					<option value="30" <%if(month.equals("30")){out.print("selected='selected'");} %>>30~50만</option>
					<option value="50" <%if(month.equals("50")){out.print("selected='selected'");} %>>50이상</option>
				</select>
		</div>		
        </td>
         <td align="right"><img src="/room/img/btn_search.gif" id="seach" style="cursor: pointer;" /><img src="/room/img/btn_first.gif" hspace="5" id="re" style="cursor: pointer;"/></td>
       </tr>
      </table>
      </div>
   
     </div>
     <div><img src="/room/img/bg_box_bottom.jpg" /></div>
     </form>
   </div>
 
<!------------------리스트 시작---------------------->  
 <div class="pt15 pl10" style="width:600px">
  <!--탭-->
   <div>
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
   <col width="77px" /> <col width="77px" /> <col width="447px" />
    <tr>
     <td><a href="#"><img src="/room/img/tab_01<%if(sort.equals("date")){out.print("_on");} %>.gif" id="datesort" onmouseover="MM_swapImage('datesort','','/room/img/tab_01_on.gif',1)" onmouseout="MM_swapImgRestore()"/></a></td>
     <td><a href="#"><img src="/room/img/tab_02<%if(sort.equals("deposit")){out.print("_on");} %>.gif" id="depositsort" onmouseover="MM_swapImage('depositsort','','/room/img/tab_02_on.gif',1)" onmouseout="MM_swapImgRestore()"/></a></td>
     <!-- <td><a href="#"><img src="/room/img/tab_03<%//if(sort.equals("month")){out.print("_on");} %>.gif" id="monthsort" onmouseover="MM_swapImage('monthsort','','/room/img/tab_03_on.gif',1)" onmouseout="MM_swapImgRestore()"/></a></td> -->
     <td class="bb2">&nbsp;</td>
   </tr>
  </table>
  </div>
 <!--탭끝-->
 <%
		if(roomList != null && roomList.size() > 0){
			giCount  = 1;
			giRecordcnt = giRecordcnt - ( giCurPage -1 ) * giPageSize;	
			giStartPos = ((giCurPage - 1) * giPageSize) + 1;
	%>
	<%for(int i=0; i<roomList.size(); i++){ %>
	<% addressModel model = (addressModel)roomList.get(i);
	model.setRoomkind(codeDao.getDtlName("500",model.getRoomkind()));
	%>
 <div class="pt10 pb10 bb1">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
   <col width="109px;" />
   <col width="329px;" />
   <col width="100px;" />
   <col width="62px;" />
   
  <tr>
    <td class="thum01"><a href="javascript:goView('<%=model.getOneroom_seq() %>')"><%if(model.getPhoto1_main().equals("1")){ %>
			<img src="/download/<%=model.getPhoto1_small() %>?name=<%=model.getPhoto1_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("2")){ %>
			<img src="/download/<%=model.getPhoto2_small() %>?name=<%=model.getPhoto2_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("3")){ %>
			<img src="/download/<%=model.getPhoto3_small() %>?name=<%=model.getPhoto3_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("4")){ %>
			<img src="/download/<%=model.getPhoto4_small() %>?name=<%=model.getPhoto4_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("5")){ %>
			<img src="/download/<%=model.getPhoto5_small() %>?name=<%=model.getPhoto5_small() %>&kind=img" />
		<%}else if(model.getPhoto1_main().equals("6")){ %>
			<img src="/download/<%=model.getPhoto6_small() %>?name=<%=model.getPhoto6_small() %>&kind=img" />
		<%} %></a></td>
    <td valign="top" class="pt5 pl10">매물종류 : <%=model.getRoomkind() %> &nbsp;&nbsp;<span class="fw"><%if(model.getTitle().length() > 15){ out.print(model.getTitle().substring(0,14)+"...");}else{ out.print(model.getTitle());} %></span><br /><br />
    임대종류 : <%if (model.getRoommoney() != ""){ %>전세&nbsp;&nbsp;<span class="c_org fs11"><strong><%=model.getRoommoney() %></strong></span>
    <%}else if(model.getRoommonth1() != ""){ %>월세&nbsp;&nbsp;<span class="c_org fs11"><strong><%=model.getRoommonth1() %>/<%=model.getRoommonth2() %></strong></span>
    <%} %>
    <br/>    
    거래방식 : <%if (model.getRoomoption().equals("D")){ out.print("<font color='#ff00ff'>직거래</font>");%>
    <%}else if(model.getRoomoption().equals("M")){ out.print("<font color='#008000'>반값중개</font>");%>
    <%}else if(model.getRoomoption().equals("G")){ out.print("<font color='#808000'>일반중개</font>");}%>    
    <br/>     
    <br/>
    위치 : <%=model.getAddress1() %>&nbsp;&nbsp;<%=model.getAddress2() %>&nbsp;&nbsp;<%=model.getAddress3() %>    
    <td valign="top" class="pt5"><%=model.getCreatedate() %>  
    <br/><%if(Integer.parseInt(model.getReport_cnt()) >= 2){%>
	&nbsp;<img src="/room/img/contract_end.gif" />
	<%} %>      
    </td>
    <td valign="top" class="pt5 fw"><%=model.getCreateid() %>
    </td>
  </tr>
</table>
</div>

<%
		giCount = giCount + 1;
		giRecordcnt = giRecordcnt - 1;
	%>
	<%} %>
	<%}else{ %>
<div class="pt10 pb10 bb1">
	  <table width="100%" border="0" cellspacing="0" cellpadding="0">
	   <col width="100%" />
	  <tr>
	  	<td>
	  		검색된 매물 정보가 없습니다.
	  	</td>
	  </tr>
	</table>
</div>

	<%} %>
<%@ include file="/room/common/zip_page.jsp" %>
<!------------------리스트 끝---------------------->  
</div>
  </div>  
<!----------------가운데 끝---------------->



<!----------------오른쪽 시작---------------->    
   <%@ include file="/room/common/right.jsp" %>
<!----------------오른쪽 끝---------------->
</div>


<!-------------푸터영역----------> 
<%@ include file="/room/common/footer.jsp" %> 

<script type="text/javascript">
swfobject.registerObject("FlashID");
</script>
<form action="area_view.jsp" method="post" name="frmView" id="frmView">
		<input type="hidden" name="roomkind" value="<%=roomkind %>" />
		<input type="hidden" name="charter" value="<%=charter %>" />
		<input type="hidden" name="zipcode2" value="<%=zipcode2 %>" />
		<input type="hidden" name="zipcode3" value="<%=zipcode3 %>" />
		
		<input type="hidden" name="deposit" value="<%=deposit %>" />
		<input type="hidden" name="month" value="<%=month %>" />
		<input type="hidden" name="sort" value="<%=sort %>" />
		<input type="hidden" name="oneroom_seq" value=""/>
	</form>
</body>
</html>
